import { SerializeClass } from "../../core/serialize";
import { Event } from "../eca/event";

@SerializeClass("EventCallMethod")
export class EventCallMethod extends Event {
    comName = "";
    methodName = "";

    hook(obj: cc.Component) {
        let hook = super.hook(obj);
        let cur = obj.node;
        if (this.comName) {
            cur = obj.getComponent(this.comName);
        }

        if (cur[this.methodName]) {
            hook.superCall = cur[this.methodName] || null;
        }
        cur[this.methodName] = () => {
            hook.trigged(obj);
        };

        return hook;
    }
};

@SerializeClass("EventClick")
export class EventClick extends Event {
    hook(obj: cc.Component) {
        let hook = super.hook(obj);
        obj.node.on(cc.Node.EventType.TOUCH_END, () => {
            hook.trigged(obj);
        });
        return hook;
    }
};
